package com.ruiysoft.mapper.sys;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ruiysoft.entity.sys.SysShopPersonnel;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import javax.validation.Valid;
import javax.validation.constraints.NotNull;
import java.util.List;

/**
 * <p>
 *  Mapper 接口
 * </p>
 *
 * @author huazengguang
 * @since 2018-11-01
 */
public interface SysShopPersonnelMapper extends BaseMapper<SysShopPersonnel> {

    List<SysShopPersonnel> selectVisitorList(@Param("shopId") Long shopId);

    void insertIgnore(SysShopPersonnel sysShopPersonnel);

    List<SysShopPersonnel> selectPersonnelList(Page<SysShopPersonnel> page, @NotNull @Valid @Param("shopId") Long shopId);

    @Select("SELECT shopPersonnel.*,distribution.name distributionName,distribution.id distributionId FROM sys_shop_personnel shopPersonnel left join sys_shop_personnel_relation relation on shopPersonnel.id=relation.personnel_id left join sys_shop_distribution distribution on relation.distributionId=distribution.id WHERE relation.shop_id=#{shopId } and shopPersonnel.id IN (SELECT parent_id FROM sys_shop_personnel_relation WHERE shop_id=#{shopId })")
    List<SysShopPersonnel> selectPersonnelRalationList(Page<SysShopPersonnel> page, @NotNull @Valid @Param("shopId") Long shopId);

    List<SysShopPersonnel> getPersonnelByParentId(Page<SysShopPersonnel> page, @NotNull @Valid @Param("shopId") Long shopId,@NotNull @Valid @Param("userId") Long userId);
}
